package com.cp.service.impl;

import com.cp.model.Userinfo;
import com.cp.model.UserinfoCriteria;
import com.cp.service.UserService;
import com.cp.service.UserinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisCluster;

import java.util.List;

@Service("userServiceL")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserinfoMapper UserinfoMapper;
    // 注入集群对象
    @Autowired
    private JedisCluster jedisCluster;


    @Cacheable(value = "findAll", keyGenerator = "wiselyKeyGenerator")
    @Override
    public List<Userinfo> findAll() {
        UserinfoCriteria UserinfoCriteria=new UserinfoCriteria() ;
        System.out.println("如果第二次没有打印此文字说明缓存存在！");
        return UserinfoMapper.selectByExample(UserinfoCriteria);
    }
    @Cacheable(value = "findById", keyGenerator = "wiselyKeyGenerator")
    @Override
    public List<Userinfo> findById(Integer id) {
        UserinfoCriteria userinfoCriteria=new UserinfoCriteria() ;
        //userinfoCriteria.andUseridEqualTo(id) ;
        System.out.println("如果第二次没有打印此文字说明缓存存在！");
        return UserinfoMapper.selectByExample(userinfoCriteria);
    }
   @Override
    public String getRedis() {
        jedisCluster.set("username", "少年包青天");
        String string = jedisCluster.get("username");
        System.out.println("集群");
        return string;

    }
}
